/**
 * 将对象的所有属性值设置为null
 * @param value - 要重置的对象
 */
export function resetToNull<T extends object>(value: T): void {
    // 获取对象自身的可枚举属性数组
    const keys = Object.keys(value);
    // 遍历属性数组
    for (const key of keys) {
        // 将属性值设置为null
        Object.assign(value, {[key]: null});
    }
}


export function is(val: any, type: string) {
    return toString.call(val) === `[object ${type}]`;
}

export function isDef<T = any>(val?: T): boolean {
    return typeof val !== 'undefined';
}

export function isObject(val: any): boolean {
    return val !== null && is(val, 'Object');
};

export function isString(val: any): boolean {
    return is(val, 'String');
}

export function isBoolean(val: any): boolean {
    return is(val, 'Boolean');
}

export function isArray(val: any): boolean {
    return val && Array.isArray(val);
}

export function isNull(val: any): boolean {
    return val === null || val === undefined;
}

export function isNotNull(val: any): boolean {
    return !isNull(val);
}

export function isEmpty(val: any): boolean {
    if (isNull(val)) {
        return true;
    }

    if (isArray(val) || isString(val)) {
        return val.length === 0;
    }

    if (val instanceof Map || val instanceof Set) {
        return val.size === 0;
    }

    return false;
}

export function isNotEmpty(val: any): boolean {
    return !isEmpty(val);
}

export function deepClone<T>(obj: T): T {
    return obj ? JSON.parse(JSON.stringify(obj)) : obj;
}
